Skip to content

ui: MenuItems.Beside opens a menu to the right of its anchor - #6

Merged
xiaoyumuxi merged 1 commit into
mainfrom
fix/menu-beside
Nov 11, 2026
Merged

xiaoyumuxi merged 1 commit into
mainfrom
fix/menu-beside

Conversation

@xiaoyumuxi

@xiaoyumuxi xiaoyumuxi commented Nov 11, 2026 •

Copy link
Copy Markdown

What this changes

MenuItems.Beside() opens a Menu to the right of its anchor, its top at the anchor's, and flips it to the left when there is no room on the right. It slides in from the edge it hangs off, as a submenu does. Above and Beside now share one field, which declareMenu resets in every paint, so a menu that stops calling one of them opens under its anchor again (before, a menu that once called Above stayed above).

The guides (en, zh) mention menu.Beside() next to menu.Above().

Why

A Menu could only open under or over its anchor. The menu of a row in a list or a popup (a branch row's actions in a branch picker, say) then covers the rows under it, which the user is still choosing among. Opening it beside the row, as a submenu opens beside its item, keeps them in sight.

How it was verified

  • test -z "$(gofmt -l $(git ls-files '*.go'))"
  • go vet ./...
  • go test ./... -count=1: everything passes except six tests of cmd/viva (TestPackage*), which fail on this machine on base too: its Xcode SDK builds for macOS 13.0 or later while the test manifests say min_system = 12.0. Nothing in this change reaches packaging.
  • platform vet: backends not touched
  • benchmarks before and after: BenchmarkMenuOpen, 5 runs each, 2304–2390 ns/op before and 2300–2365 ns/op after, 0 B/op and 0 allocs/op both
  • stripped binary size: what links did not change beyond one method
  • a real window: not yet. The placement is checked by TestMenuBeside on the headless driver; the Lithe desktop branch picker, the first caller, will be checked in a real macOS window once it adopts Beside.

Visual evidence

  • Changed: a Menu whose body calls menu.Beside()
  • Reach it by: TestMenuBeside's page: click "More" with beside set
  • Evidence: the first item's bounds start right of the anchor's and level with it
  • On: macOS, light theme, scale 2
  • Protected by: TestMenuBeside (beside the anchor, then under it again once Beside is gone)

Where the boundary sits

Framework capability: placement of an overlay against its anchor, which Box.BesideBox already offers to popups; Menu only did not expose it.

Cost

None for a program that does not call Beside: one switch on a byte in place of a bool test.

A Menu opened from a row of a list or popup covered the rows under it,
since it could only open under or over its anchor. Beside places it to the
right of the anchor, its top at the anchor's, flipping to the left when
there is no room, and slides it in from that edge. The side a Menu opens
on is now asked again in every paint, so a menu that stops calling Above
or Beside opens under its anchor again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant